﻿#include "setup3wind.h"
#include "ui_setup3wind.h"
#include <mainwindow.h>
extern intListener doorStatus;
setup3wind::setup3wind(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::setup3wind)
{
    setWindowIcon(QIcon(":/pic/picture/kafavicon.ico"));
    ui->setupUi(this);
    connect(&doorStatus, &intListener::valueChanged,this,&setup3wind::doorStatusChanged,Qt::QueuedConnection);
    ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    ui->pushButton_9->setEnabled(false);
}
void setup3wind::doorStatusChanged(){
    if(doorStatus.get()==0)
    {
        ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
}

setup3wind::~setup3wind()
{
    delete ui;
}

void setup3wind::showEvent(QShowEvent *event){
    eqptinfo eqInfo;
    ui->pushButton->setText(QString("设备运行时长 h\n %1").arg(eqInfo.operhread().split(':')[0]));
    ui->pushButton_2->setText(QString("检测时长\n %1").arg(eqInfo.durahread()));
    ui->pushButton_3->setText(QString("试验次数\n %1").arg(eqInfo.timesread()));
    ui->pushButton_4->setText(QString("总检测样本数\n %1").arg(eqInfo.sampelsumread()));

    tcpClient = TcpClient::getInstance();
    if(doorStatus.get()==0)
    {
        ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    ThresholdDetection();
    event->accept();
}

void setup3wind::on_returnBtn_clicked()
{
    this->close();
    emit changeTotalWindow();
}

void setup3wind::on_SaveBtn_clicked()
{
    this->close();
    emit changeTotalWindow();
}

void setup3wind::on_pushButton_9_clicked()
{
    if(doorStatus.get()==0)
    {
        doorStatus.set(1);
        ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
    else
    {
        doorStatus.set(0);
        ui->pushButton_9->setStyleSheet("background-color: rgba(0, 0, 0, 0.3);");
    }
}

void setup3wind::ThresholdDetection(){
    eqptinfo eqInfo;
    int orgOper= eqInfo.operhread().toInt();
    int threOper = eqInfo.operThreRead().toInt();
    if(orgOper>threOper){
        ui->pushButton->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu5.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton->setEnabled(true);
    }else {
        ui->pushButton->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu1.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton->setEnabled(false);
    }


    QTime orgDura= QTime::fromString(eqInfo.durahread(), "hh:mm:ss");
    QTime threDura=QTime::fromString(eqInfo.duraThreRead(), "hh:mm:ss");
    if(orgDura>threDura)
    {
        ui->pushButton_2->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu5.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton_2->setEnabled(true);
    }
    else
    {
        ui->pushButton_2->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu2.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton_2->setEnabled(false);
    }

    int orgTimes=eqInfo.timesread().toInt();
    int threTimes=eqInfo.timesThreRead().toInt();
    if(orgTimes>threTimes)
    {
        ui->pushButton_3->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu5.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton_3->setEnabled(true);
    }
    else
    {
        ui->pushButton_3->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu3.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton_3->setEnabled(false);
    }

    int orgSampleSum=eqInfo.sampelsumread().toInt();
    int threSampleSum=eqInfo.sampleSumThreRead().toInt();
    if(orgSampleSum>threSampleSum)
    {
        ui->pushButton_4->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu5.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton_4->setEnabled(true);
    }
    else
    {
        ui->pushButton_4->setStyleSheet("background: #FFF6F0;border-image: url(:/pic/picture/shu4.png);border-radius: 0px 12px 12px 0px;");
        ui->pushButton_4->setEnabled(false);
    }
}

void setup3wind::on_pushButton_clicked()
{
    tcts *tctsWindow = new tcts();
    tctsWindow->infochange("提示","info","设备运行时长超时,\n请及时检修!\n如有问题,请联系技术支持",false,true);
    tctsWindow->show();
}

void setup3wind::on_pushButton_2_clicked()
{
    tcts *tctsWindow = new tcts();
    tctsWindow->infochange("提示","info","检测时长超时,\n请及时检修!\n如有问题,请联系技术支持",false,true);
    tctsWindow->show();
}

void setup3wind::on_pushButton_3_clicked()
{
    tcts *tctsWindow = new tcts();
    tctsWindow->infochange("提示","info","试验次数超出限定值,\n请及时检修!\n如有问题,请联系技术支持",false,true);
    tctsWindow->show();
}

void setup3wind::on_pushButton_4_clicked()
{
    tcts *tctsWindow = new tcts();
    tctsWindow->infochange("提示","info","总检测样本数超出限定值,\n请及时检修!\n如有问题,请联系技术支持",false,true);
    tctsWindow->show();
}
